Object.defineProperty(exports, "__esModule", {
  value: true
});
var $z1Subpub = require("Subpub");
var def_Tool = function () {
  function _ctor() {}
  _ctor.init = function (t) {
    var o = cc.find("Canvas");
    _ctor.ScreenWH[0] = o.width;
    _ctor.ScreenWH[1] = o.height;
    _ctor.BattlegroundBoard[0] = t.x - t.width / 2;
    _ctor.BattlegroundBoard[1] = t.x + t.width / 2;
    _ctor.BattlegroundBoard[2] = t.y - t.height / 2;
    _ctor.BattlegroundBoard[3] = t.y + t.height / 2;
    cc.director.getCollisionManager().enabled = true;
  };
  _ctor.isInBattleGround = function (t, o) {
    return t >= _ctor.BattlegroundBoard[0] - 100 && t <= _ctor.BattlegroundBoard[1] + 100 && o >= _ctor.BattlegroundBoard[2] - 100 && o <= _ctor.BattlegroundBoard[3] + 100;
  };
  _ctor.getAngle = function (e, t) {
    if (0 === e) {
      if (0 === t) {
        return 0;
      } else {
        if (t > 0) {
          return 90;
        } else {
          return 270;
        }
      }
    }
    if (0 === t) {
      if (e > 0) {
        return 0;
      } else {
        return 180;
      }
    }
    var o = 180 * Math.atan(Math.abs(t) / Math.abs(e)) / Math.PI;
    if (t > 0) {
      e < 0 && (o = 180 - o);
    } else {
      o = e > 0 ? 360 - o : 180 + o;
    }
    return o;
  };
  _ctor.setValueTo = function (e, t, o) {
    if (e < t) {
      return t;
    } else {
      if (e > o) {
        return o;
      } else {
        return e;
      }
    }
  };
  _ctor.isInEllipse = function (e, t, o, a, n, i) {
    return (e - o) * (e - o) / (n * n) + (t - a) * (t - a) / (i * i) <= 1;
  };
  _ctor.isInRect = function (e, t, o, a, n, i) {
    return e >= o - n / 2 && e <= o + n / 2 && t >= a - i / 2 && t <= a + i / 2;
  };
  _ctor.randomPointInNode = function (e) {
    return [e.x - e.width / 2 + Math.random() * e.width, e.y - e.height / 2 + Math.random() * e.height];
  };
  _ctor.randomInt = function (e, t) {
    return Math.floor(Math.random() * (t - e + 1)) + e;
  };
  _ctor.randomFromArr = function (e) {
    return e[Math.floor(Math.random() * e.length)];
  };
  _ctor.randomFromArr2 = function (e, t) {
    if (e.length <= t) {
      return e;
    }
    if (t <= 0) {
      return [];
    }
    var o = [];
    var a = e.map(function (e) {
      return e;
    });
    for (var n = 0; n < t; n++) {
      var i = Math.floor(Math.random() * (a.length - n));
      o.push(a[i]);
      a[i] = a[a.length - 1 - n];
    }
    return o;
  };
  _ctor.randomByWeight = function (e, t) {
    undefined === t && (t = []);
    var o = [];
    var a = 0;
    var n = {};
    t.map(function (e) {
      n[e] = 1;
    });
    for (var i = 0; i < e.length; i++) {
      if (!n[i]) {
        o.push({
          idx: i,
          w: e[i]
        });
        a += e[i];
      }
    }
    var c = Math.random() * a;
    for (i = 0; i < o.length; i++) {
      if (c < o[i].w) {
        return o[i].idx;
      }
      c -= o[i].w;
    }
    console.log("Tools.randombyWeight发生未知错误：", o, a, c);
  };
  _ctor.getPrefab = function (e, t, o) {
    var a = e.getChildByName(o);
    if (!a) {
      (a = cc.instantiate(t)).setParent(e);
      a.name = o;
    }
    a.active = true;
    return a;
  };
  _ctor.showVideoAd = function (e, t) {
    cc.pvz.AdUtils.showAdRewardVideo(e, function (e) {
      e && t();
    });
  };
  _ctor.formatBigNum3 = function (e) {
    if (e < 1e4) {
      return "" + e;
    } else {
      if (e % 1e3 == 0) {
        return e / 1e3 + "K";
      } else {
        return (e / 1e3).toFixed(1) + "K";
      }
    }
  };
  _ctor.resetGamePauseInfo = function () {
    _ctor.gameTimeScale = 1;
    _ctor.gamePause = 0;
  };
  _ctor.pauseGame = function () {
    _ctor.gamePause = 1;
    $z1Subpub.default.publishEx("Spine.SetTimeScale", {
      timeScale: 0
    });
  };
  _ctor.resumeGame = function () {
    _ctor.gamePause = 0;
    $z1Subpub.default.publishEx("Spine.SetTimeScale", {
      timeScale: _ctor.gameTimeScale
    });
  };
  _ctor.setGameTimeScale = function (t) {
    _ctor.gameTimeScale = t;
    _ctor.gamePause || $z1Subpub.default.publishEx("Spine.SetTimeScale", {
      timeScale: t
    });
  };
  _ctor.copyArr = function (t) {
    undefined === t && (t = []);
    var o = [];
    for (var a = 0; a < t.length; a++) {
      if (Array.isArray(t[a])) {
        o.push(_ctor.copyArr(t[a]));
      } else {
        o.push(t[a]);
      }
    }
    return o;
  };
  _ctor.getRGBColor = function (e) {
    var t = [0, 0, 0];
    for (var o = 0; o < 3; o++) {
      t[o] = parseInt("0x" + e[2 * o + 1] + e[2 * o + 2]);
    }
    return new cc.Color(t[0], t[1], t[2]);
  };
  _ctor.shuffle = function (e) {
    for (var t = 0; t < e.length; t++) {
      var o = Math.floor(Math.random() * (e.length - t)) + t;
      var a = e[t];
      e[t] = e[o];
      e[o] = a;
    }
    return e;
  };
  _ctor.ScreenWH = [0, 0];
  _ctor.BattlegroundBoard = [0, 0, 0, 0];
  _ctor.inSceneTest = 1;
  _ctor.gameTimeScale = 1;
  _ctor.gamePause = 0;
  return _ctor;
}();
exports.default = def_Tool;